<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2012
 */

/**
 *
 *
 */
class RbacCommand extends CConsoleCommand {
	private $_authManager;
	public function run() {
		if(($this->_authManager=Yii::app()->authManager)===null) {
			echo "Error: an authorization manager, named 'authManager'
				must be configured to use this command.\n";
			echo "If you already added 'authManager' component in
				application configuration,\n";
			echo "please quit and re-enter the yiic shell.\n";
			return;
		}

		$this->_authManager->clearAll();

		$this->_authManager->createOperation("create","create");
		$this->_authManager->createOperation("read","read");
		$this->_authManager->createOperation("update","update");
		$this->_authManager->createOperation("delete","remove");

		$role=$this->_authManager->createRole('reader');
		$role->addChild('read');

		$role=$this->_authManager->createRole('employee');
		$role->addChild('reader');
		$role->addChild('create');
		$role->addChild('update');

		$role=$this->_authManager->createRole('admin');
		$role->addChild('employee');
		$role->addChild('delete');
	}
}
?>